import React, { Component } from 'react'
// WrappedComponent 用来接收需要使用Demo组件中状态和逻辑的组件. 本质上就是一个形参,只是行业中一般都叫这个名字
export default function withDemo(WrappedComponent) {
  return class Demo extends Component {
    state = {
      username: '',
      password: '',
      repassword: '',
    }

    handleChange = (name) => {
      return (e) => {
        this.setState({
          [name]: e.target.value,
        })
      }
    }
    render() {
      return (
        <WrappedComponent
          username={this.state.username}
          password={this.state.password}
          repassword={this.state.repassword}
          handleChange={this.handleChange}
        ></WrappedComponent>
      )
    }
  }
}
